<?php defined('MINICAKE') or exit('can not access!');
/**
 * LocalDB
 * 
 * @package 
 * @version $id$
 * @copyright 
 * @author lovise <lovise.lu@gmail.com> 
 * @license PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}
 */
class MyDB {
	/**
	 * con 
	 * 
	 * @var mixed
	 * @access public
	 */
	var $con = null;
	/**
	 * __construct 
	 * 
	 * @access protected
	 * @return void
	 */
	function __construct(){
		$servername = Configure::getItem('servername');
		$username = Configure::getItem('username');
		$password = Configure::getItem('password');
		$db = Configure::getItem('db');
		$this->con = mysql_connect($servername,$username,$password);
		if(!$this->con){
			die("连接数据库失败");
		}
		mysql_select_db($db,$this->con);
	}
    /**
     * 设置当前连接的字符集 , 必须在发起连接之前进行设置
     *
     * @param string $charset 字符集,如GBK,GB2312,UTF8
     * @return void 
     */
    function setCharset( $charset )
    {
        return mysql_query("SET NAMES $charset");
    }
    /**
     * rulSql 
     * 
     * @param mixed $sql 
     * @access public
     * @return void
     */
    function rulSql($sql){
		return mysql_query($sql);
	}
    /**
     * getData 
     * 
     * @param mixed $sql 
     * @access public
     * @return void
     */
    function getData($sql){
		$result = mysql_query($sql,$this->con);
		if (is_bool($result)) {
			return $result;
		} else {
			while( $Array = mysql_fetch_array($result) ) {
				$data[$i++] = $Array;
			}
		}
		if( count( $data ) > 0 )
			return $data;
		else
			return false;
	}
	/**
	 * getLine 
	 * 
	 * @param mixed $sql 
	 * @access public
	 * @return void
	 */
	function getLine($sql){
		$data = $this->getData($sql);
		if($data){
			return reset($data);
		}else{
			return false;
		}
	}
	/**
	 * closeDB 
	 * 
	 * @access public
	 * @return void
	 */
	function closeDB(){
		mysql_close($this->con);
	}
	/**
	 * __destruct 
	 * 
	 * @access protected
	 * @return void
	 */
	function __destruct(){
	}
}
?>
